package leo.game.ui
{
	import flash.display.Shape;
	import flash.display.Sprite;
	
	import leo.data.GameConst;

	/**
	 * 生命条 
	 * @author leo
	 * 
	 */	
	public class UILife extends Sprite
	{
		/**
		 * 底层红色框 
		 */		
		private var bottomLayer :Shape;
		/**
		 * 上层血条 
		 */		
		private var topLayer :Shape;
		public function UILife()
		{
			super();
			this.bottomLayer = new Shape();
			this.topLayer = new Shape();
			initLife();
		}
		
		private function initLife():void
		{
			bottomLayer.graphics.lineStyle(2,0xff0000,0.5);
			bottomLayer.graphics.drawRoundRect(0,0,GameConst.TILE_WIDTH/2,5,10,10);
			bottomLayer.graphics.endFill();
			
			this.addChild(bottomLayer);
			
			topLayer.graphics.beginFill(0x7FFF00);
			topLayer.graphics.drawRoundRect(0,0,GameConst.TILE_WIDTH/2,5,10,10);
			topLayer.graphics.endFill();
			this.addChild(topLayer);
			
		}
		/**
		 * 更新生命条显示状态 
		 * @param value
		 * 
		 */		
		public function updateLife(value :Number):void
		{
			if(this.topLayer.width < 0)
			{
				return;
			}
			this.topLayer.width -= value;
			
		}
		
		/**
		 * 销毁 
		 * 
		 */		
		public function destroy():void
		{
			this.removeChild(this.bottomLayer);
			this.removeChild(this.topLayer);
		}

	}
}